package com.escope.casemanager.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * Administrator
 * 2024/3/15
 */
@ApiModel("HTTP响应对象")
public class HttpResult implements Serializable {
    @ApiModelProperty("响应码， 200成功, 500 失败")
    private Integer code;
    @ApiModelProperty(value = "响应消息")
    private String msg;
    @ApiModelProperty("响应数据")
    private Object data;


    public HttpResult() {
        code = 200;
        msg = "success";
    }

    public static HttpResult ok() {
        HttpResult r = new HttpResult();
        return r;
    }

    public static HttpResult ok(Object data) {
        HttpResult r = new HttpResult();
        r.setData(data);
        return r;
    }

    public static HttpResult ok(Object data, String msg) {
        HttpResult r = new HttpResult();
        r.setData(data);
        r.setMsg(msg);
        return r;
    }

    public static HttpResult ok(Integer code, Object data, String msg) {
        HttpResult r = new HttpResult();
        r.setCode(code);
        r.setData(data);
        r.setMsg(msg);
        return r;
    }

    public static HttpResult error() {
        HttpResult r = new HttpResult();
        r.setCode(500);
        r.setMsg("未知异常，请联系管理员");
        return r;
    }

    /**
     * .
     *
     * @param msg .
     */
    public static HttpResult error(String msg) {
        HttpResult r = new HttpResult();
        r.setCode(500);
        r.setMsg(msg);
        return r;
    }

    /**
     * .
     *
     * @param data .
     * @param msg .
     */
    public static HttpResult error(Object data, String msg) {
        HttpResult r = new HttpResult();
        r.setCode(500);
        r.setData(data);
        r.setMsg(msg);
        return r;
    }

    /**
     * .
     *
     * @param code .
     * @param data .
     * @param msg .
     */
    public static HttpResult error(Integer code, Object data, String msg) {
        HttpResult r = new HttpResult();
        r.setCode(code);
        r.setData(data);
        r.setMsg(msg);
        return r;
    }

    public static HttpResult loginError() {
        HttpResult r = new HttpResult();
        r.setCode(-1);
        r.setMsg("请登录！");
        return r;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
